package com.suqiu.qqrobot.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.suqiu.qqrobot.config.OpenAiChatContext;
import com.suqiu.qqrobot.service.AiChatService;
import com.unfbx.chatgpt.entity.chat.Message;

import java.util.ArrayList;

interface OpenAiChatService<T, R> extends AiChatService<T, R> {

    default ArrayList<Message> getMessages(OpenAiChatContext context, String sessionId, String question) {
        Message message = Message.builder().role(Message.Role.ASSISTANT).content(question).build();
        ArrayList<Message> messages = context.get(sessionId);
        if (CollectionUtil.isEmpty(messages)) {
            messages = new ArrayList<>();
        }
        messages.add(message);
        // 保存上下文
        context.put(sessionId, messages);
        return messages;
    }


}
